package com.example.demo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.Period;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class json {
   // @ResponseBody
    @RequestMapping("getMap")
    public Map<String,String> getMap(){
        Map<String,String> map=new HashMap<>();
        map.put("a","1");
        map.put("b","v1");
        map.put("c","v2");
        return map;
    }
    @RequestMapping("setstatus")
    public String setstatus(HttpServletResponse httpServletResponse){
        httpServletResponse.setStatus(400);
        return "状态码设置成功";
    }
    @RequestMapping("returnjson")
    public List<Person> returnjson(){
        List<Person>list=new ArrayList<>();
        Person person=new Person("zhangsan",18);
        list.add(person);
        return list;
    }
    @ResponseBody
    @RequestMapping(value = "setContent-Type",produces = "application/json")
    public String setContent_Type (HttpServletResponse httpServletResponse){
        return "\"123\"";
    }
}
